/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package feverquery;

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Jose Luis
 */
@ManagedBean
@SessionScoped
public class FeverController implements Serializable {

    private static String OS = System.getProperty("os.name").toLowerCase();
    FeverHelper helper;
    private DataModel userPlans;
    private DataModel userXml;
    private DataModel userPlanXml;
    private DataModel userInvitator;
    private DataModel userExcel;
    private DataModel updateDataBase;
    private DataModel userExcelInvitator;
    private String name;
    private String surname;
    private String nameInvitator;
    private String surnameInvitator;
    private String ageInvitator;
    private String searchBy;
    private String fbid;
    private String selectedContact;
    private List<String> contacts;
    private String plan;
    private String selectedContactInvitator;
    private String selectedGenderInvitator;
    private String selectedStyleInvitator;
    private String selectedInfluenceInvitator;
    private String selectedImageInvitator;
    private List<String> contactsInvitator;
    private List<String> genderInvitator;
    private List<String> influenceInvitator;
    private List<String> imageInvitator;
    private List<String> styleInvitator;
    private String selectedPlan;
    private List<String> plans;
    private List<String> plansSearch;
    private ExcelUsers[] selectedExcelUsers;
    private boolean matchCase;
    private boolean hidePlans;
    private String selectedUsersFB;
    private String selectedPlanSearch;
    private String selectedNameLast;
    private String age1, age2;
    private final String rangeAge1 = "16";
    private final String rangeAge2 = "99";
    private List<String> selectedStylesInvitator;
    private List<String> selectedImagesInvitator;
    private List<ExcelUsers> ex_us;

    /**
     * Creates a new instance of FeverController
     */
    public FeverController() {
        helper = new FeverHelper();
        this.name = "";
        this.surname = "";
        this.nameInvitator = "";
        this.surnameInvitator = "";
        this.ageInvitator = "";
        //this.nameInvitations = "";
        this.searchBy = "User";
        this.fbid = "";
        this.plan = "";

        this.contacts = new LinkedList<String>();
        this.contactsInvitator = new LinkedList<String>();
        this.genderInvitator = new LinkedList<String>();
        this.styleInvitator = new LinkedList<String>();
        this.influenceInvitator = new LinkedList<String>();
        this.imageInvitator = new LinkedList<String>();

        this.selectedContact = "";
        this.selectedContactInvitator = "";
        this.selectedGenderInvitator = "";
        this.selectedStyleInvitator = "";
        this.selectedInfluenceInvitator = "";
        this.selectedImageInvitator = "";
        this.selectedPlan = "";
        this.selectedPlanSearch = "";
        this.selectedStylesInvitator = new LinkedList<String>();
        this.selectedImagesInvitator = new LinkedList<String>();


        setMatchCase(true);
        setHidePlans(false);

        plans = helper.getPlansName();
        plansSearch = helper.getPlansName();
        List<String> c = helper.getContacts();
        contacts = c;
        contactsInvitator = c;
        genderInvitator = helper.getGender();
        influenceInvitator = helper.getInfluence();
        imageInvitator = helper.getImage();
        styleInvitator = helper.getStyle();
        age1 = rangeAge1;
        age2 = rangeAge2;

        ex_us = new LinkedList<ExcelUsers>();
    }

    public FeverController(String name, String surname) {
        helper = new FeverHelper();
        this.name = name;
        this.surname = surname;
    }

    void recreateModel() {
        setUserPlans(null);
        setUserXml(null);
        setUserPlanXml(null);
        setUserInvitator(null);
        setUserExcel(null);
        setUserExcelInvitator(null);
        setUpdateDataBase(null);
    }

    public void exportExcel() {
        try {
            String plan = "";
            if (ex_us.size() > 0) {
                File textFile = null;
                plan = ex_us.get(0).getPlansid();
                int p = plan.indexOf(")");
                if (p == -1) {
                    Random r = new Random(100);
                    plan = "Excel_Fever_" + r.nextInt();
                } else {
                    plan = plan.substring(p + 1);
                }

                String filename = plan + ".xls";
                if (isWindows()) {
                    //String userHomeFolder = "C:";
                    //textFile = new File(userHomeFolder, filename);
                    String userHomeFolder = System.getProperty("user.home")+File.separator+"Documents"+File.separator;
                    //filename = fw.getDefaultDirectory()+File.separator+filename;
                    textFile = new File(userHomeFolder,filename);
                    System.out.println(filename);
                } else if (isMac()) {
                    String userHomeFolder = System.getProperty("user.home");
                    textFile = new File(userHomeFolder,filename);
                }

                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("FirstSheet");

                HSSFRow rowf = sheet.createRow(0);
                rowf.createCell(0).setCellValue("PLAN: " + ex_us.get(0).getPlansid());

                HSSFRow rowf2 = sheet.createRow(1);

                HSSFRow rowhead = sheet.createRow(2);
                rowhead.createCell(0).setCellValue("Plan");
                rowhead.createCell(1).setCellValue("Referral");
                rowhead.createCell(2).setCellValue("Name");
                rowhead.createCell(3).setCellValue("Last Name");
                rowhead.createCell(4).setCellValue("Facebook Id");
                rowhead.createCell(5).setCellValue("Avisado");
                rowhead.createCell(6).setCellValue("Confirmado");

                int s = ex_us.size();
                for (int i = 0; i < s; i++) {
                    HSSFRow row = sheet.createRow(i + 3);
                    row.createCell(0).setCellValue(ex_us.get(i).getPlansid());
                    row.createCell(1).setCellValue(ex_us.get(i).getContacto());
                    row.createCell(2).setCellValue(ex_us.get(i).getNombre());
                    row.createCell(3).setCellValue(ex_us.get(i).getApellidos());
                    row.createCell(4).setCellValue(ex_us.get(i).getFacebookId());
                    row.createCell(5).setCellValue("");
                    row.createCell(6).setCellValue("");
                }

                FileOutputStream fileOut = new FileOutputStream(textFile);
                workbook.write(fileOut);
                fileOut.close();
                System.out.println("Your excel file has been generated in " + textFile.getAbsolutePath());
            }
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }

    public void userExcel() {
        //setUserExcel(new ListDataModel(helper.getUserExcel(getName(), getSurname(), getSelectedContact())));
        ex_us = helper.getUserExcel(getSelectedPlanSearch(), getName(), getSurname(), getSelectedContact());
        setUserExcel(new ListDataModel(ex_us));
    }

    public void userExcelInvitator() {
        if (isMatchCase()) {
            setUserExcelInvitator(new ListDataModel(helper.getUsersExcelInvitationsExact(getSelectedGenderInvitator(), getAge1(), getAge2(), getSelectedStylesInvitator(), getSelectedInfluenceInvitator(), getSelectedImagesInvitator(), getNameInvitator(), getSurnameInvitator(), getSelectedContactInvitator(), getSelectedPlan(), isHidePlans())));
        } else {
            setUserExcelInvitator(new ListDataModel(helper.getUsersExcelInvitationsNotExact(getSelectedGenderInvitator(), getAge1(), getAge2(), getSelectedStylesInvitator(), getSelectedInfluenceInvitator(), getSelectedImagesInvitator(), getNameInvitator(), getSurnameInvitator(), getSelectedContactInvitator(), getSelectedPlan(), isHidePlans())));
        }
        //setUserInvitator(new ListDataModel(helper.getUsersInvitations2(getNameInvitator(), getSurnameInvitator(), getSelectedContactInvitator(), getSelectedPlan())));
        //setSelectedExcelUsers(new ExcelUsers[0]);
    }

    public void addPlan() {
        long num = helper.getNumbPlans();
        helper.addPlan(getPlan(), num + 1);
        this.plans();
    }

    public void updateDatabase() {
        ExcelUsers[] ex = getSelectedExcelUsers();
        int i = ex.length;
        long id;
        String plan = getSelectedPlan();
        for (int j = 0; j < i; j++) {
            id = helper.getNumContacs();
            helper.update(id + 1, ex[j].getNombre(), ex[j].getApellidos(), ex[j].getSexo(), ex[j].getEdad(), ex[j].getEstilo(), ex[j].getInfluencia(), ex[j].getImagen(), ex[j].getFacebookId(), ex[j].getColegio(), ex[j].getUniversidad(), ex[j].getTrabajo(), ex[j].getZona(), ex[j].getOtros(), ex[j].getEMail(), ex[j].getTelefono(), plan, ex[j].getContacto());
        }
    }

    public void contacts() {
        setContacts(helper.getContacts());
    }

    public void contactsInvitator() {
        setContactsInvitator(helper.getContacts());
    }

    public void genderInvitator() {
        setGenderInvitator(helper.getGender());
    }

    public void styleInvitator() {
        setStyleInvitator(helper.getStyle());
    }

    public void influenceInvitator() {
        setInfluenceInvitator(helper.getInfluence());
    }

    public void imageInvitator() {
        setImageInvitator(helper.getImage());
    }

    public void plans() {
        List<String> plans = helper.getPlansName();
        setPlans(plans);
        setPlansSearch(plans);
    }

    public void getSendFBNotification() {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Invitation(s) sent", "The invitation was sent to the selected people");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public void destroyWorld() {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "System Error", "Please try again later.");

        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    private void setNameLastName(ExcelUsers[] selectedExcelUsers) {
        String select = "";
        String aux = "";
        if (selectedExcelUsers != null && (selectedExcelUsers.length > 0)) {
            select = selectedExcelUsers[0].getNombre() + " " + selectedExcelUsers[0].getApellidos();
            for (int i = 1; i < selectedExcelUsers.length; i++) {
                //Replace blank space for null string could alter the FB ids
                aux = selectedExcelUsers[i].getNombre() + " " + selectedExcelUsers[i].getApellidos();//.replace(" ", "");
                select += ", " + aux;
            }
        }
        setSelectedNameLast(select);
    }

    private void setFB(ExcelUsers[] selectedUsers) {
        String selectedfb = "";
        String aux = "";
        if (selectedUsers != null && (selectedUsers.length > 0)) {
            selectedfb = selectedUsers[0].getFacebookId();
            for (int i = 1; i < selectedUsers.length; i++) {
                //Replace blank space for null string could alter the FB ids
                aux = selectedUsers[i].getFacebookId();//.replace(" ", "");
                selectedfb += "," + aux;
            }
        }
        setSelectedUsersFB(selectedfb);
    }

    /**
     * @return the searchBy
     */
    public String getSearchBy() {
        return searchBy;
    }

    /**
     * @param searchBy the searchBy to set
     */
    public void setSearchBy(String searchBy) {
        this.searchBy = searchBy;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }

    /**
     * @return the userPlans
     */
    public DataModel getUserPlans() {
        return userPlans;
    }

    /**
     * @param userPlans the userPlans to set
     */
    public void setUserPlans(DataModel userPlans) {
        this.userPlans = userPlans;
    }

    /**
     * @return the nameInvitations
     */
    /*public String getNameInvitations() {
     if (name == null && surname == null) {
     nameInvitations = "";
     } else if (name != "" || surname != "") {
     nameInvitations = name + " " + surname + " was invited to the following plans";
     }

     return nameInvitations;
     }

     public void setNameInvitations(String nameInvitations) {
     this.nameInvitations = nameInvitations;
     }*/
    /**
     * @return the userXml
     */
    public DataModel getUserXml() {
        return userXml;
    }

    /**
     * @param userXml the userXml to set
     */
    public void setUserXml(DataModel userXml) {
        this.userXml = userXml;
    }

    /**
     * @return the fbid
     */
    public String getFbid() {
        return fbid;
    }

    /**
     * @param fbid the fbid to set
     */
    public void setFbid(String fbid) {
        this.fbid = fbid;
    }

    /**
     * @return the userplanxml
     */
    public DataModel getUserPlanXml() {
        return userPlanXml;
    }

    /**
     * @param userplanxml the userplanxml to set
     */
    public void setUserPlanXml(DataModel userplanxml) {
        this.userPlanXml = userplanxml;
    }

    /**
     * @return the selectedContact
     */
    public String getSelectedContact() {
        return selectedContact;
    }

    /**
     * @param selectedContact the selectedContact to set
     */
    public void setSelectedContact(String selectedContact) {
        this.selectedContact = selectedContact;
    }

    /**
     * @return the contacts
     */
    public List<String> getContacts() {
        return contacts;
    }

    /**
     * @param contacts the contacts to set
     */
    public void setContacts(List<String> contacts) {
        this.contacts = contacts;
    }

    /**
     * @return the selectedPlan
     */
    public String getSelectedPlan() {
        return selectedPlan;
    }

    /**
     * @param selectedPlan the selectedPlan to set
     */
    public void setSelectedPlan(String selectedPlan) {
        this.selectedPlan = selectedPlan;
    }

    /**
     * @return the plans
     */
    public List<String> getPlans() {
        return plans;
    }

    /**
     * @param plans the plans to set
     */
    public void setPlans(List<String> plans) {
        this.plans = plans;
    }

    /**
     * @return the nameInvitator
     */
    public String getNameInvitator() {
        return nameInvitator;
    }

    /**
     * @param nameInvitator the nameInvitator to set
     */
    public void setNameInvitator(String nameInvitator) {
        this.nameInvitator = nameInvitator;
    }

    /**
     * @return the surnameInvitator
     */
    public String getSurnameInvitator() {
        return surnameInvitator;
    }

    /**
     * @param surnameInvitator the surnameInvitator to set
     */
    public void setSurnameInvitator(String surnameInvitator) {
        this.surnameInvitator = surnameInvitator;
    }

    /**
     * @return the selectedContactInvitator
     */
    public String getSelectedContactInvitator() {
        return selectedContactInvitator;
    }

    /**
     * @param selectedContactInvitator the selectedContactInvitator to set
     */
    public void setSelectedContactInvitator(String selectedContactInvitator) {
        this.selectedContactInvitator = selectedContactInvitator;
    }

    /**
     * @return the contactsInvitator
     */
    public List<String> getContactsInvitator() {
        return contactsInvitator;
    }

    /**
     * @param contactsInvitator the contactsInvitator to set
     */
    public void setContactsInvitator(List<String> contactsInvitator) {
        this.contactsInvitator = contactsInvitator;
    }

    /**
     * @return the userInvitator
     */
    /*public DataModel getUserInvitator() {
     return userInvitator;
     }*/
    /**
     * @param userInvitator the userInvitator to set
     */
    /*public void setUserInvitator(DataModel userInvitator) {
     this.userInvitator = userInvitator;
     }*/
    /**
     * @return the userInvitator
     */
    public DataModel getUserInvitator() {
        return userInvitator;
    }

    /**
     * @param userInvitator the userInvitator to set
     */
    public void setUserInvitator(DataModel userInvitator) {
        this.userInvitator = userInvitator;
    }

    /**
     * @return the matchCase
     */
    public boolean isMatchCase() {
        return matchCase;
    }

    /**
     * @param matchCase the matchCase to set
     */
    public void setMatchCase(boolean matchCase) {
        this.matchCase = matchCase;
    }

    /**
     * @return the hidePlans
     */
    public boolean isHidePlans() {
        return hidePlans;
    }

    /**
     * @param hidePlans the hidePlans to set
     */
    public void setHidePlans(boolean hidePlans) {
        this.hidePlans = hidePlans;
    }

    /**
     * @return the selectedUsersFB
     */
    public String getSelectedUsersFB() {
        return selectedUsersFB;
    }

    /**
     * @param selectedUsersFB the selectedUsersFB to set
     */
    public void setSelectedUsersFB(String selectedUsersFB) {
        this.selectedUsersFB = selectedUsersFB;
    }

    /**
     * @return the userExcel
     */
    public DataModel getUserExcel() {
        return userExcel;
    }

    /**
     * @param userExcel the userExcel to set
     */
    public void setUserExcel(DataModel userExcel) {
        this.userExcel = userExcel;
    }

    /**
     * @return the userExcelInvitator
     */
    public DataModel getUserExcelInvitator() {
        return userExcelInvitator;
    }

    /**
     * @param userExcelInvitator the userExcelInvitator to set
     */
    public void setUserExcelInvitator(DataModel userExcelInvitator) {
        /*ExcelUsers list = (ExcelUsers) userExcelInvitator.getRowData();
         List<String> fb = new LinkedList<String>();
         ExcelUsers e;
         for (Iterator it = userExcelInvitator.iterator(); it.hasNext();) {
         e = (ExcelUsers) it.next();
         if (!fb.contains(e.getFacebookId())) {
         fb.add(e.getFacebookId());
         }else{
                
         }
         }*/
        this.userExcelInvitator = userExcelInvitator;
    }

    /**
     * @return the selectedExcelUsers
     */
    public ExcelUsers[] getSelectedExcelUsers() {
        return selectedExcelUsers;
    }

    /**
     * @param selectedExcelUsers the selectedExcelUsers to set
     */
    public void setSelectedExcelUsers(ExcelUsers[] selectedExcelUsers) {
        this.setFB(selectedExcelUsers);
        this.setNameLastName(selectedExcelUsers);
        this.selectedExcelUsers = selectedExcelUsers;
    }

    /**
     * @return the ageInvitator
     */
    public String getAgeInvitator() {
        return ageInvitator;
    }

    /**
     * @param ageInvitator the ageInvitator to set
     */
    public void setAgeInvitator(String ageInvitator) {
        this.ageInvitator = ageInvitator;
    }

    /**
     * @return the genderInvitator
     */
    public List<String> getGenderInvitator() {
        return genderInvitator;
    }

    /**
     * @param genderInvitator the genderInvitator to set
     */
    public void setGenderInvitator(List<String> genderInvitator) {
        this.genderInvitator = genderInvitator;
    }

    /**
     * @return the influenceInvitator
     */
    public List<String> getInfluenceInvitator() {
        return influenceInvitator;
    }

    /**
     * @param influenceInvitator the influenceInvitator to set
     */
    public void setInfluenceInvitator(List<String> influenceInvitator) {
        this.influenceInvitator = influenceInvitator;
    }

    /**
     * @return the imageInvitator
     */
    public List<String> getImageInvitator() {
        return imageInvitator;
    }

    /**
     * @param imageInvitator the imageInvitator to set
     */
    public void setImageInvitator(List<String> imageInvitator) {
        this.imageInvitator = imageInvitator;
    }

    /**
     * @return the styleInvitator
     */
    public List<String> getStyleInvitator() {
        return styleInvitator;
    }

    /**
     * @param styleInvitator the styleInvitator to set
     */
    public void setStyleInvitator(List<String> styleInvitator) {
        this.styleInvitator = styleInvitator;
    }

    /**
     * @return the selectedGenderInvitator
     */
    public String getSelectedGenderInvitator() {
        return selectedGenderInvitator;
    }

    /**
     * @param selectedGenderInvitator the selectedGenderInvitator to set
     */
    public void setSelectedGenderInvitator(String selectedGenderInvitator) {
        this.selectedGenderInvitator = selectedGenderInvitator;
    }

    /**
     * @return the selectedStyleInvitator
     */
    public String getSelectedStyleInvitator() {
        return selectedStyleInvitator;
    }

    /**
     * @param selectedStyleInvitator the selectedStyleInvitator to set
     */
    public void setSelectedStyleInvitator(String selectedStyleInvitator) {
        this.selectedStyleInvitator = selectedStyleInvitator;
    }

    /**
     * @return the selectedInfluenceInvitator
     */
    public String getSelectedInfluenceInvitator() {
        return selectedInfluenceInvitator;
    }

    /**
     * @param selectedInfluenceInvitator the selectedInfluenceInvitator to set
     */
    public void setSelectedInfluenceInvitator(String selectedInfluenceInvitator) {
        this.selectedInfluenceInvitator = selectedInfluenceInvitator;
    }

    /**
     * @return the selectedImageInvitator
     */
    public String getSelectedImageInvitator() {
        return selectedImageInvitator;
    }

    /**
     * @param selectedImageInvitator the selectedImageInvitator to set
     */
    public void setSelectedImageInvitator(String selectedImageInvitator) {
        this.selectedImageInvitator = selectedImageInvitator;
    }

    /**
     * @return the plan
     */
    public String getPlan() {
        return plan;
    }

    /**
     * @param plan the plan to set
     */
    public void setPlan(String plan) {
        this.plan = plan;
    }

    /**
     * @return the plansSearch
     */
    public List<String> getPlansSearch() {
        return plansSearch;
    }

    /**
     * @param plansSearch the plansSearch to set
     */
    public void setPlansSearch(List<String> plansSearch) {
        this.plansSearch = plansSearch;
    }

    /**
     * @return the selectedPlanSearch
     */
    public String getSelectedPlanSearch() {
        return selectedPlanSearch;
    }

    /**
     * @param selectedPlanSearch the selectedPlanSearch to set
     */
    public void setSelectedPlanSearch(String selectedPlanSearch) {
        this.selectedPlanSearch = selectedPlanSearch;
    }

    /**
     * @return the updateDataBase
     */
    public DataModel getUpdateDataBase() {
        return updateDataBase;
    }

    /**
     * @param updateDataBase the updateDataBase to set
     */
    public void setUpdateDataBase(DataModel updateDataBase) {
        this.updateDataBase = updateDataBase;
    }

    /**
     * @return the selectedNameLast
     */
    public String getSelectedNameLast() {
        return selectedNameLast;
    }

    /**
     * @param selectedNameLast the selectedNameLast to set
     */
    public void setSelectedNameLast(String selectedNameLast) {
        this.selectedNameLast = selectedNameLast;
    }

    /**
     * @return the age1
     */
    public String getAge1() {
        return age1;
    }

    /**
     * @param age1 the age1 to set
     */
    public void setAge1(String age1) {
        this.age1 = age1;
    }

    /**
     * @return the age2
     */
    public String getAge2() {
        return age2;
    }

    /**
     * @param age2 the age2 to set
     */
    public void setAge2(String age2) {
        this.age2 = age2;
    }

    /**
     * @return the rangeAge1
     */
    public String getRangeAge1() {
        return rangeAge1;
    }

    /**
     * @return the rangeAge2
     */
    public String getRangeAge2() {
        return rangeAge2;
    }

    /**
     * @return the selectedStylesInvitator
     */
    public List<String> getSelectedStylesInvitator() {
        return selectedStylesInvitator;
    }

    /**
     * @param selectedStylesInvitator the selectedStylesInvitator to set
     */
    public void setSelectedStylesInvitator(List<String> selectedStylesInvitator) {
        this.selectedStylesInvitator = selectedStylesInvitator;
    }

    /**
     * @return the selectedImagesInvitator
     */
    public List<String> getSelectedImagesInvitator() {
        return selectedImagesInvitator;
    }

    /**
     * @param selectedImagesInvitator the selectedImagesInvitator to set
     */
    public void setSelectedImagesInvitator(List<String> selectedImagesInvitator) {
        this.selectedImagesInvitator = selectedImagesInvitator;
    }

    public static boolean isWindows() {

        return (OS.indexOf("win") >= 0);

    }

    public static boolean isMac() {

        return (OS.indexOf("mac") >= 0);

    }

    public static boolean isUnix() {

        return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0);

    }

    public static boolean isSolaris() {

        return (OS.indexOf("sunos") >= 0);

    }
}
